//
//  WSPlayView.m
//  GroupFourFM
//
//  Created by dllo on 15/12/25.
//  Copyright © 2015年 GroupFour. All rights reserved.
//

#import "WSPlayView.h"

@implementation WSPlayView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self createSubviews];
    }
    
    return self;
}

-(void)createSubviews
{
    self.backgroundImageView = [[UIImageView alloc] init];
    self.backgroundImageView.backgroundColor = [UIColor blueColor];
    [self addSubview:self.backgroundImageView];
    [self.backgroundImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.left.right.mas_equalTo(@0);
        make.height.mas_equalTo(SCREEN_WIDTH * 1.30);
    }];
    
    UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
    UIVisualEffectView *visualEffectView = [[UIVisualEffectView alloc]initWithEffect:blurEffect];
    [visualEffectView setFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_WIDTH * 1.30)];
    [self.backgroundImageView addSubview:visualEffectView];
    
    
    //音乐图片
    self.musicImageView = [[UIImageView alloc] init];
    self.musicImageView.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.musicImageView];
    [self.musicImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(self.backgroundImageView);
        make.centerY.equalTo(self.backgroundImageView).offset(-20);
        make.width.height.equalTo(self.backgroundImageView.mas_width).multipliedBy(0.65);
    }];
    
    self.playBarView = [[WSBaseImageView alloc] init];
    [self addSubview:self.playBarView];
    self.playBarView.backgroundColor = WHITE;
    self.playBarView.userInteractionEnabled = YES;
    [self.playBarView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.right.mas_equalTo(@0);
        make.top.equalTo(self.backgroundImageView.mas_bottom);
        make.height.mas_equalTo(80);
    }];
    
    //进度条
    self.progressSlider = [[UISlider alloc] init];
    self.progressSlider.backgroundColor = [UIColor colorWithRed:0.73 green:0.73 blue:0.73 alpha:1];
    [self addSubview:self.progressSlider];
    self.progressSlider.minimumTrackTintColor = COLOR_SELECTED;
    self.progressSlider.maximumTrackTintColor = COLOR_BG;
    [self.progressSlider setThumbImage:[UIImage imageNamed:@"playProcessDot_n"] forState:UIControlStateNormal];
    [self.progressSlider mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.right.mas_equalTo(@0);
        make.bottom.equalTo(self.backgroundImageView.mas_bottom);
        make.height.mas_equalTo(@3);
    }];
    
    self.timeLabelLeft = [[UILabel alloc] init];
    self.timeLabelLeft.backgroundColor = CLEAR;
    self.timeLabelLeft.text = @"00:00";
    self.timeLabelLeft.font = [UIFont systemFontOfSize:13];
    self.timeLabelLeft.textColor = [UIColor colorWithRed:0.52 green:0.52 blue:0.59 alpha:1];
    [self addSubview:self.timeLabelLeft];
    [self.timeLabelLeft mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(@0);
        make.bottom.equalTo(self.progressSlider.mas_top).offset(-5);
        make.width.mas_equalTo(@100);
        make.height.mas_equalTo(@20);
    }];
    
    self.timeLabelRight = [[UILabel alloc] init];
    self.timeLabelRight.backgroundColor = CLEAR;
    self.timeLabelRight.text = @"00:00";
    self.timeLabelRight.textAlignment = NSTextAlignmentRight;
    self.timeLabelRight.font = [UIFont systemFontOfSize:13];
    self.timeLabelRight.textColor = [UIColor colorWithRed:0.52 green:0.52 blue:0.59 alpha:1];
    [self addSubview:self.timeLabelRight];
    [self.timeLabelRight mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(@0);
        make.bottom.equalTo(self.progressSlider.mas_top).offset(-5);
        make.width.mas_equalTo(@100);
        make.height.mas_equalTo(@20);
    }];
    
    //播放列表
    self.listButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.listButton.backgroundColor = CLEAR;
    [self.listButton setImage:[UIImage imageNamed:@"toolbar_playinglist_n_p"] forState:UIControlStateNormal];
    [self.listButton setImage:[UIImage imageNamed:@"toolbar_playinglist_h_p"] forState:UIControlStateHighlighted];
    [self.playBarView addSubview:self.listButton];
    [self.listButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(self.playBarView).multipliedBy(0.2);
        make.centerY.equalTo(self.playBarView);
        make.width.height.equalTo(self.playBarView.mas_width).multipliedBy(0.2);
    }];
    
    // 播放模式
    self.playType = [UIButton buttonWithType:UIButtonTypeCustom];
    self.playType.backgroundColor = CLEAR;
    [self.playType setBackgroundImage:[UIImage imageNamed:@"iconfont-xunhuan.png"] forState:UIControlStateNormal];
    [self addSubview:self.playType];
    [self.playType mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(self);
        make.top.equalTo(self.musicImageView.mas_bottom).offset(20);
        make.width.mas_equalTo(20);
        make.height.mas_equalTo(20);
    }];
    
    //播放历史
    self.historyButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.historyButton.backgroundColor = CLEAR;
    [self.historyButton setImage:[UIImage imageNamed:@"toolbar_history_n_p"] forState:UIControlStateNormal];
    [self.historyButton setImage:[UIImage imageNamed:@"toolbar_history_h_p"] forState:UIControlStateHighlighted];
    [self.playBarView addSubview:self.historyButton];
    [self.historyButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(self.playBarView).multipliedBy(1.8);
        make.centerY.equalTo(self.playBarView);
        make.width.height.equalTo(self.playBarView.mas_width).multipliedBy(0.2);
    }];
    
    UIImageView *imageBg = [[UIImageView alloc] init];
    imageBg.image = [UIImage imageNamed:@"toolbar_loading_n_p"];
    imageBg.backgroundColor = CLEAR;
    [self.playBarView addSubview:imageBg];
    [imageBg mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(self.playBarView);
        make.centerY.equalTo(self.playBarView);
        make.width.height.equalTo(self.playBarView.mas_width).multipliedBy(0.17);
    }];
    
    //播放按钮
    self.playButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.playButton.backgroundColor = CLEAR;
    [self.playButton setImage:[UIImage imageNamed:@"toolbar_pause_h_p"] forState:UIControlStateNormal];
    [self.playBarView addSubview:self.playButton];
    [self.playButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(self.playBarView);
        make.centerY.equalTo(self.playBarView);
        make.width.height.equalTo(self.playBarView.mas_width).multipliedBy(0.2);
    }];
    
    //上一首按钮
    self.upButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.upButton.backgroundColor = CLEAR;
    [self.upButton setImage:[UIImage imageNamed:@"toolbar_prev_n_p"] forState:UIControlStateNormal];
    [self.playBarView addSubview:self.upButton];
    [self.upButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.listButton.mas_right);
        make.right.equalTo(imageBg.mas_left);
        make.centerY.equalTo(self.playBarView);
        make.height.equalTo(self.playBarView.mas_width).multipliedBy(0.2);
    }];
    
    //下一首按钮
    self.nextButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.nextButton.backgroundColor = CLEAR;
    [self.nextButton setImage:[UIImage imageNamed:@"toolbar_next_n_p"] forState:UIControlStateNormal];
    [self.playBarView addSubview:self.nextButton];
    [self.nextButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(imageBg.mas_right);
        make.right.equalTo(self.historyButton.mas_left);
        make.centerY.equalTo(self.playBarView);
        make.height.equalTo(self.playBarView.mas_width).multipliedBy(0.2);
    }];
    
}

@end
